var USER_CONDITION_TPL = `<div style="padding:5px;">
	<el-row :gutter="20">
		<el-col :span="6">
			<el-input v-model="condition" placeholder="请输入条件"></el-input>
		</el-col>
		<el-col :span="2">
			<el-button @click="search" icon="el-icon-search" type="primary">查询</el-button>
		</el-col>
		<el-col :span="2">
			<el-button @click="add" icon="el-icon-plus" type="success">添加</el-button>
		</el-col>
		<el-col :span="2">
			<el-button @click="visible=true" icon="el-icon-plus" type="warning">自动添加</el-button>
		</el-col>
	</el-row>
	<el-dialog title="输入自动生成用户个数" :visible.sync="visible" width="50%" >
		<el-form label-width="80px">
			<el-form-item label="数量">
				<el-input v-model="size"></el-input>
			</el-form-item>
		</el-form>
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false">取 消</el-button>
			<el-button type="primary" @click="autoAdd">确 定</el-button>
		</span>
	</el-dialog>
</div>`;

Vue.component('UserConditionComponent', {
    template: USER_CONDITION_TPL,
	data: function(){
    	return {
			parent: null,
			condition: "",
			size: 0,
			visible: false,
    	}
    },
    mounted: function(){},
	methods: {
		init: function(app){ this.parent = app },
		search: function (){
			var user_table = this.parent.$refs.user_table
			if(user_table){
				user_table.search({cond: this.condition})
			}
		},
		add: function(){
			var user_edit = this.parent.$refs.user_edit
			if(user_edit){
				user_edit.add()
			}
		},
		autoAdd: function(){
			var that = this;
			var uri = '/user/autoAdd'
			axios.post(uri, {
				size: this.size
			}).then(function (res) {
            	console.log(res.data)
				that.search()
				that.visible = false
			}).catch(function (error) {
				console.error(error);
			}).then(function () {});
		}
	}
})